#include "TestSensor.h"
#include <ooputils/ConfigManager.h>
#include <fstream>
#include <sstream>


using namespace OOPUtils;


TestSensor::TestSensor (const OOPString& configPath) : _curFrame (0)
{
	_loadTestFile (ConfigManager::getSingleton ().getBasePath () + configPath);
}


TestSensor::~TestSensor ()
{
}

std::vector< glm::dvec3 > TestSensor::detectFingerPoints ()
{
	if (_curFrame >= _testFingerPoints.size ())
		return std::vector< glm::dvec3 > ();
	return _testFingerPoints[_curFrame++];
}

void TestSensor::_loadTestFile (const OOPString& testFilePath)
{
	std::ifstream inStream (testFilePath);
	while (inStream) {
		std::string strLine;
		std::getline (inStream, strLine);
		if (strLine == "") continue;

		std::istringstream lineStream (strLine);
		_testFingerPoints.push_back (std::vector< glm::dvec3 > ());
		while (lineStream) {
			glm::dvec3 fingerPoint;
			lineStream >> fingerPoint[0] >> fingerPoint[1] >> fingerPoint[2];
			if (lineStream)
				_testFingerPoints[_testFingerPoints.size () - 1].push_back (fingerPoint);
		}
	}
}